<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>My JSP 'storageBoxCodeList.jsp' starting page</title>
		<script type="text/javascript">
		   var boxTypeStatus=${boxTypeStatus};
		   function inStorage(){
		      boxTypeStatus=0;
		      window.location.href="${ctx}/boxinStorage/init/"+boxTypeStatus;
		   }
		   
		    function outStorage(){
		      boxTypeStatus=1;
		      window.location.href="${ctx}/boxinStorage/init/"+boxTypeStatus;
		   }
		   function outPutBoxCode(){
		     	var shippedBatch = $("#search_LIKE_boxCode").val() + "";
			    	if(shippedBatch.trim()==""){
			    	  $("#search_LIKE_boxCode").attr("name", "ordeno");
			    	}
		     $("#outPutBoxForm").attr("action","${ctx}/boxinStorage/init/"+boxTypeStatus);
		     $("#outPutBoxForm").submit();
		     $("#search_LIKE_boxCode").attr("name", "search_LIKE_boxCode");
		   }
		   
	function waitMyChecked(item) {
		if ($("#check_wait" + item).is(":checked")) {

		} else {
			$("#waitMyCheckedAll").attr("checked", false);
		}
	}
	
	function waitMyCheckedAll() {
		$("input[name='waitMyChecked']").attr("checked",
				$("#waitMyCheckedAll").is(":checked"));
	}
	
	 function waitMyCheckedAllString() {
		var tempChecked = "";
		$("input[type='checkbox'][name='waitMyChecked']:checked").each(function() {
		if(tempChecked==""){
		  tempChecked+=$(this).val();
		}else{
	    	tempChecked = tempChecked + ":" + $(this).val();
		}
		});
		return tempChecked;
	}
		
	function ajaxPutOutStorage() {
	var tempString = "";
	var storageListIds=waitMyCheckedAllString();
	if(storageListIds==""){
	$("#message")
									.html(
											"<button data-dismiss=\"alert\" class=\"close\">×</button>请选择箱子");
							$("#message").attr("class", "alert alert-block");
							setTimeout(function() {
								$("#message").removeClass();
								$("#message").html("");
							}, 6000);
	  return;
	}
		$
				.ajax({
					type : 'post',
					url : '${ctx}/boxinStorage/ajaxPutOutStorage',
					data : 'storageListIds=' +storageListIds,
					dataType : 'json',
					success : function(data) {
						
						if (data.status == "1") {
						   setHide(storageListIds);
							$("#message")
									.html(
											"<button data-dismiss=\"alert\" class=\"close\">×</button>领用成功");
							$("#message").attr("class", "alert alert-success");
							setTimeout(function() {
								$("#message").removeClass();
								$("#message").html("");
							}, 6000);
						}  else if (data.status == "0") {
						$("#message")
									.html(
											"<button data-dismiss=\"alert\" class=\"close\">×</button>服务器异常！");
							$("#message").attr("class", "alert alert-block");
						}

						$("#boxMessage").html(tempString);
					},

					error : function() {
	$("#message")
									.html(
											"<button data-dismiss=\"alert\" class=\"close\">×</button>服务器异常！");
							$("#message").attr("class", "alert alert-block");
						

						$("#boxMessage").html(tempString);
					}
				});
	} 
	
	function setHide(storageListIds){
	  var storageListIdString=storageListIds.split(":");
	  for(var i=0;i<storageListIdString.length;i++){
	    $("#in"+storageListIdString[i]).hide();
	  }
	}
		</script>

	</head>

	<body>
		<div id="message">

		</div>
		<div class="span12">
			<form class="form-search" method="post" id="form_solr">

				<label>
					批次：
				</label>
				<input type="text" name="search_LIKE_batchCode" class="input-medium"
					value="${param.search_LIKE_batchCode}" id="search_LIKE_batchCode">
				<label>
					商家：
				</label>
				<select id="customersCode" name="search_LIKE_customers.customerName"
					onchange="changeCustomersCode()">
					<c:forEach items="${customers}" var="customer">

						<option value="${customer.customerName}"
							<c:if test="${customer.customerName eq customersCustomerName}">selected</c:if>>
							${customer.customerName}
						</option>
					</c:forEach>
				</select>
				<label for="pmsprinters_corpLevel" class="control-label">
					库区:
				</label>

				<select id="storages" name="search_LIKE_storage.name"
					onchange="companyAjaxExpressStyle()">
					<c:forEach items="${storages}" var="storage">
						<option value="${storage.name}"
							<c:if test="${storageName eq  storage.name}">selected</c:if>>
							${storage.name}
						</option>
					</c:forEach>
				</select>

				<label>
					类型：
				</label>
				<select id="boxType" name="search_LIKE_boxType">
					<option value="single"
						<c:if test="${param.search_LIKE_boxType eq  'single'}">selected</c:if>>
						单件
					</option>
					<option value="multiple"
						<c:if test="${param.search_LIKE_boxType eq  'multiple'}">selected</c:if>>
						多件
					</option>

				</select>
				<button type="submit" class="btn" id="submitForm_solr">
					搜索
				</button>

			</form>
			<script type="text/javascript">
			    $("#submitForm_solr").click(function(){
			    	var shippedBatch = $("#search_LIKE_batchCode").val() + "";
			    	if(shippedBatch.trim()==""){
			    	  $("#search_LIKE_batchCode").attr("name", "ordeno");
			    	}
		         $("#form_solr").attr("action","${ctx}/boxinStorage/init/"+boxTypeStatus);
		         $("#form_solr").submit();
		         $("#search_LIKE_batchCode").attr("name", "search_LIKE_batchCode");
		   });
			</script>
		</div>
		<form class="form-search" id="outPutBoxForm">
			<label for="pmsprinters_corpLevel" class="control-label">
				箱子条码:
				<input type="text" id="boxCode" name="search_LIKE_boxCode"
					value="${param.search_LIKE_boxCode }" id="search_LIKE_boxCode"
					onchange="outPutBoxCode()" />
			</label>
		</form>
		<div>
			<button id="printer" class="btn btn-primary"
				onclick="ajaxPutOutStorage();">
				领用出仓
			</button>
		</div>
		<div class="tabbable">
			<!-- Only required for left/right tabs -->
			<ul class="nav nav-tabs">
				<li class="${inActive }">
					<a href="#tab1" data-toggle="tab" onclick="inStorage();">在库<span
						id="fold"></span> </a>
				</li>
				<li class="${outActive }">
					<a href="#tab2" data-toggle="tab" onclick="outStorage();">出库<span
						id="unfold"></span> </a>
				</li>
			</ul>
			<div class="tab-content">
				<div class="tab-pane ${inActive }" id="tab1">
					<table class="table table-striped table-bordered table-condensed"
						id="fold_tab">
						<thead>
							<tr>
								<th style="width: 50px;">
									全选:
									<input type="checkbox" name="waitMyCheckedAll"
										id="waitMyCheckedAll" onclick="waitMyCheckedAll()" />
								</th>

								<th>
									库区
								</th>
								<th>
									批次
								</th>

								<th>
									箱子
								</th>
								<th>
									类型
								</th>
								<th>
									商家
								</th>

								<th>
									操作人
								</th>
								<th>
									时间
								</th>
								<th>
									箱子货物差异
								</th>
							</tr>
						</thead>
						<tbody id="tbodyChecked">
							<c:forEach items="${pageBoxinStorageIns.content}"
								var="pageBoxinStorageIn">
								<tr id="in${pageBoxinStorageIn.id }">
									<td align="right">
										<input type="checkbox" name="waitMyChecked"
											id="check_wait${pageBoxinStorageIn.boxCode}"
											value="${pageBoxinStorageIn.id}"
											onclick="waitMyChecked(${pageBoxinStorageIn.boxCode})" />
									</td>

									<td>
										${pageBoxinStorageIn.storage.name}
									</td>

									<td>
										${pageBoxinStorageIn.batchCode}
									</td>
									<td>
										${pageBoxinStorageIn.boxCode}
									</td>
									<td>
										<c:if test="${pageBoxinStorageIn.boxType eq 'single'}">
									     一单一件
									   </c:if>
										<c:if test="${pageBoxinStorageIn.boxType eq 'multiple'}">
									     一单多件
									   </c:if>
									</td>
									<td>
										${pageBoxinStorageIn.customers.customerName}
									</td>

									<td>
										<c:forEach items="${users }" var="user">
											<c:if test="${pageBoxinStorageIn.jobuuid eq user.jobuuid}">
									   ${user.realname }
									 </c:if>
										</c:forEach>

									</td>
									<td>
										${pageBoxinStorageIn.created}
									</td>
									<td>
									 ${pageBoxinStorageIn.goodsStatus}
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<tags:pagination page="${pageBoxinStorageIns}" paginationSize="5" />

				</div>
				<div class="tab-pane ${outActive }" id="tab2">
					<table class="table table-striped table-bordered table-condensed"
						id="unfold_tab">
						<thead>
							<tr>



								<th>
									库区
								</th>
								<th>
									批次
								</th>

								<th>
									箱子
								</th>
								<th>
									类型
								</th>
								<th>
									商家
								</th>

								<th>
									操作人
								</th>
								<th>
									时间
								</th>
                                 <th>
									箱子货物差异
								</th>
							</tr>
						</thead>
						<tbody id="tbodyChecked">
							<c:forEach items="${pageBoxinStorageOuts.content}"
								var="pageBoxinStorageOut">
								<tr id="${pageBoxinStorageOut.id}">
									<td>
										${pageBoxinStorageOut.storage.name}
									</td>

									<td>
										${pageBoxinStorageOut.batchCode}
									</td>
									<td>
										${pageBoxinStorageOut.boxCode}
									</td>
									<td>
										<c:if test="${pageBoxinStorageOut.boxType eq 'single'}">
									     一单一件
									   </c:if>
										<c:if test="${pageBoxinStorageOut.boxType eq 'multiple'}">
									     一单多件
									   </c:if>
									</td>
									<td>
										${pageBoxinStorageOut.customers.customerName}
									</td>

									<td>
										<c:forEach items="${users }" var="user">
											<c:if test="${pageBoxinStorageOut.jobuuid eq user.jobuuid}">
									   ${user.realname }
									 </c:if>
										</c:forEach>

									</td>
									<td>
										${pageBoxinStorageOut.updated}
									</td>
									<td>
									    ${pageBoxinStorageOut.goodsStatus}
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<tags:pagination page="${pageBoxinStorageOuts}" paginationSize="5" />
				</div>
			</div>
		</div>


	</body>
</html>
